#ifndef SINGLETON_H
#define SINGLETON_H

#include <boost/scoped_ptr.hpp>
#include <boost/thread/once.hpp>
#include <boost/utility.hpp>

template<class T>
class Singleton : private boost::noncopyable
{
public:

	static T* GetAddress()
	{
		boost::call_once(Initialize, mFlag);
		return mInstance.get();
	}
	static T& GetReference()
	{
		boost::call_once(Initialize, mFlag);
		return *mInstance;
	}

protected:

	Singleton()
	{
	}
	~Singleton()
	{
	}

private:

	static void Initialize()
	{
		mInstance.reset(new T);
	}

	static boost::once_flag mFlag;
	static boost::scoped_ptr<T> mInstance;
};

template<class T> boost::scoped_ptr<T> Singleton<T>::mInstance(NULL);
template<class T> boost::once_flag Singleton<T>::mFlag = BOOST_ONCE_INIT;

#endif
